/* 
 * File:   Table.cpp
 * Author: Guilherme Monteiro
 * 
 */

#include "../headers/Table.h"

Table::Table(string p) : File(p) {
}

Table::Table(const Table& orig) : File(orig) {
}

Table::~Table() {
}

void Table::writeFields(vector<string> f) {
    string line = "images";
    string tab = ","; // can to replace to \t
    for(int i = 0; i < f.size(); i++) {
        line += tab.append(f.at(i));
        //cout << "line in field (finalLine): " << line << endl;
        tab = ",";   // can to replace to \t
    }
    printf("%s\n", line.c_str());
    writeLine(line);
}

void Table::writeLineWithValues(vector<double> values, int numberLine) {
    string line;
    string tab = ",";    // can to replace to \t
    char* strNumberLine = new char[10];
    sprintf(strNumberLine, "%d", numberLine);
    line.append(strNumberLine);
    for(int i = 0; i < values.size(); i++) {
        char* strValue = new char[10];
        sprintf(strValue, "%-.2f", values.at(i));
        line.append(tab.append(strValue));
        tab = ",";  // can to replace to \t
    }
    //printf("%s\n", line.c_str());
    writeLine(line);
}

vector<string> Table::getFields() {
    return this->fields;
}

void Table::setFields(vector<string> f) {
    this->fields = f;
}

void Table::setLegend(string l) {
    this->legend = l;
}

string Table::getLegend() {
    return this->legend;
}

void Table::writeLegend(vector<string> lNames) {
    writeLine("\n----------------------------------------------------\n");
    string endLine = "\n";
    for(int i = 0; i < lNames.size(); i++) {
        legend.append(lNames.at(i).append(endLine));
        endLine = "\n";
    }
    printf("\n%s\n", this->legend.c_str());
    writeLine(getLegend());
}